package hk.m4s.lr.repair.test.ui.goods;

import android.content.Context;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.view.View;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.List;

import framework.common.baseui.UeBaseActivity;
import hk.m4s.lr.repair.test.R;
import hk.m4s.lr.repair.test.model.CouponModel;
import hk.m4s.lr.repair.test.model.SelectCouponModel;
import hk.m4s.lr.repair.test.ui.adapter.SelectNoCouponAdapter;
import hk.m4s.lr.repair.test.ui.adapter.SlectCouponAdapter;

/**
 * Created by qi.wang on 2017/11/29.
 * 选择优惠券
 */

public class SlectCouponActivity extends UeBaseActivity{
    private TabLayout mTabLayout;
    private ListView selectCouponListView,noVlist;
    private List<SelectCouponModel> couponModelList=new ArrayList<>();
    private List<SelectCouponModel> noSouponModelList=new ArrayList<>();
    private SlectCouponAdapter adapter;
    private SelectNoCouponAdapter noCouponAdapter;
    private Context context;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        baseSetContentView(R.layout.activity_select_coupon_layout);
        hiddenFooter();
        showGoBackBtn();
        context=this;
        setTitleText("使用优惠券");
        showView();
        adapter=new SlectCouponAdapter(context,couponModelList);
        selectCouponListView.setAdapter(adapter);
        noCouponAdapter=new SelectNoCouponAdapter(context,noSouponModelList);
        noVlist.setAdapter(noCouponAdapter);
        showSelect();
    }
    public void showView(){
        mTabLayout= (TabLayout) findViewById(R.id.tabs);
        selectCouponListView= (ListView) findViewById(R.id.vlist);
        noVlist= (ListView) findViewById(R.id.noVlist);
        mTabLayout.setTabMode(TabLayout.MODE_FIXED);
        mTabLayout.addTab(mTabLayout.newTab().setText("可用优惠券"), true);
        mTabLayout.addTab(mTabLayout.newTab().setText("不可用优惠券"));
        mTabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                if (tab.getPosition() == 0) {
                    noVlist.setVisibility(View.GONE);
                    selectCouponListView.setVisibility(View.VISIBLE);
                    showSelect();
                } else {
                    noVlist.setVisibility(View.VISIBLE);
                    selectCouponListView.setVisibility(View.GONE);
                    showNoSelect();
                }

            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });
    }
    public void showSelect(){
        couponModelList.clear();
        SelectCouponModel model=new SelectCouponModel();
        model.setCouponName("全场通用");
        model.setCouponPrice("100");
        model.setStartTime("2017-04-06");
        model.setEndTime("2017-08-09");
        model.setCouponTips("订单满1000元使用1张");
        model.setCouponRule("本券只能在购买指定商品时使用");
        SelectCouponModel models=new SelectCouponModel();
        models.setCouponName("全场通用");
        models.setCouponPrice("200");
        models.setStartTime("2017-04-06");
        models.setEndTime("2017-08-09");
        models.setCouponTips("订单满500元使用1张");
        models.setCouponRule("本券只能在购买指定商品时使用");
        couponModelList.add(model);
        couponModelList.add(models);

        adapter.notifyDataSetChanged();
    }
    public void showNoSelect(){
        noSouponModelList.clear();
        SelectCouponModel model=new SelectCouponModel();
        model.setCouponName("全场通用");
        model.setCouponPrice("100");
        model.setStartTime("2017-04-06");
        model.setEndTime("2017-08-09");
        model.setCouponTips("订单满1000元使用1张");
        model.setCouponRule("本券只能在购买指定商品时使用");
        SelectCouponModel models=new SelectCouponModel();
        models.setCouponName("全场通用");
        models.setCouponPrice("200");
        models.setStartTime("2017-04-06");
        models.setEndTime("2017-08-09");
        models.setCouponTips("订单满500元使用1张");
        models.setCouponRule("本券只能在购买指定商品时使用");
        noSouponModelList.add(model);
        noSouponModelList.add(models);
        noCouponAdapter.notifyDataSetChanged();
    }
}
